﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SolutionEdit.aspx.cs" ValidateRequest="false"
    Inherits="Habito.Admini.SolutionEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server"><title>ProductDetail</title>
    <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/kindeditor-all-min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/kindeditor_zh_cn.js"></script>
    <script src="../Scripts/common.js" type="text/javascript"></script>
    <link rel="stylesheet" href="../../Content/kindeditor_default/default.css" />
    <script type="text/javascript">

        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="Content"]', {
                resizeType: 1,
                allowPreviewEmoticons: true,
                allowImageUpload: true,
                allowFileManager: true,
                allowUpload: true,
                uploadJson: "../Admini/upload_json.ashx",
                fileManagerJson: '../Admini/file_manager_json.ashx',
                items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
						'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
						'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
						'superscript', 'clearhtml', 'quickformat', 'selectall', '|',
						'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
						'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
						 'table', 'hr', 'pagebreak',
						'anchor', 'link', 'unlink', '|', 'about']
            });
        });
        $(document).ready(function () {
            var id = $("#id").val();

            if (id != "" && id != 0) {
                $.ajax({
                    url: window.location.href + "&GetSolutionByID=1",
                    data: {},
                    cache: false,
                    success: function (data) {
                        data = $.evalJSON(data);
                        if (data != undefined) {
                            if (data.Description != null) {
                                editor.insertHtml(data.Description);
                            }
                            $("#title").val(data.Title);
                            $("#classes").val(data.ClassID);
                            $("#showInClass").val(data.ShowInClass);
                            $("#showIndex").val(data.ShowInIndex);
                        }
                    },
                    error: function (data) {
                    }
                });
            }
            else {
            }
        });

        function save() {
            var id = $("#id").val();
            if (id == "") {
                id = 0;
            }
            var title = $("#title").val();
            if (title == "") {
                alert("Title must be not null!");
                return;
            }

            var classid = $("#classes :selected").val();
            var productName = $("#title").val();
            var showindex = $("#showIndex :selected").val();
            var desc = escape(editor.html());
            var showInClass = $("#showInClass :selected").val();
            $.ajax({
                url: window.location.href + "&SaveSolution=1",
                cache: false,
                data: "classID=" + classid + "&showIndex=" + showindex + "&title=" + productName + "&showInClass=" + showInClass + "&description=" + desc,
                success: function (data) {
                    if (data) {
                        alert("Save Success");
                        location.href = "Solution.aspx";
                    }
                },
                error: function (data) {
                    alert();
                }
            });
        }
        function cancel() {
            location.href = "Solution.aspx";
        }
    </script>
</head>
<body>
    <div>
        <input type="hidden" name="" id="id" value="<%=ViewState["id"] %>" />
        Title:<input type="text" name="name" id="title" value="" />
        <div>Class:
			<select id="classes">
                <%=ViewState["options"]%>
            </select>
            ShowInIndex:<select id="showIndex">
                <option value="0">No</option>
                <option value="1">Yes</option>
            </select>
            ShowInClass:<select id="showInClass">
                <option value="0">No</option>
                <option value="1">Yes</option>
            </select>
            <input type="button" name="" value="Save" onclick="save()" />
            <input type="button" name="" value="Cancel" onclick="cancel()" />
        </div>
        <textarea id="txtContent" name="Content" cols="80" rows="40"></textarea>
    </div>
</body>
</html>
